import { reactive } from 'vue';

export default function (reducer, initialState) {
  //使用vue3 reactive 创建响应式数据
  const state = reactive(initialState);

  const dispatch = (type) => {
    return function (payload) {
      //传入state数据和action对象
      reducer(state, { type, payload });
    };
  };

  //返回状态和修改状态的方法
  return [state, dispatch];
}
